/*
day52_2
2019.10.20
*/

#include<stdio.h>
#include<stdlib.h>
#define MAXSIZE 1024
#define MID(left,right) ( (left)+( ((right)-(left))/2 ) )
struct TreeNode {
	int val;
	struct TreeNode *left;
	struct TreeNode *right;
};


struct TreeNode* sortedArrayToBST(int* nums, int left,int right)
{
	if(right<left) return NULL;
	int mid=MID(left,right);
	struct TreeNode *root=(struct TreeNode *)malloc(sizeof(struct TreeNode));
	root->val=nums[mid];
	root->left=sortedArrayToBST(nums,left,mid-1);
	root->right=sortedArrayToBST(nums,mid+1,right);
	return root;
}

struct TreeNode* sortedArrayToBST(int* nums, int numsSize)
{
	return	sortedArrayToBST(nums,0,numsSize-1);
}

int main()
{
	int a[]={-10,-3,0,5,9};
	sortedArrayToBST(a,5);
	
	return 0;
}
